package com.datasure.repository.impl;

import com.datasure.converter.DeviceDataConverter;
import com.datasure.domain.entity.DeviceDetail;
import com.datasure.presistence.mapper.DeviceExDOMapper;
import com.datasure.presistence.mapper.DeviceMapper;
import com.datasure.repository.base.Repository;
import com.datasure.types.LongId;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author zhangxiaolong
 * @ClassName DeviceDetailRepository.java
 * @Description DeviceDetailRepository实现类
 * @createTime 2022年01月13日 11:54:00
 */
public class DeviceDetailRepositoryImpl implements Repository<DeviceDetail, LongId> {
    @Autowired
    private DeviceMapper deviceMapper;

    @Autowired
    private DeviceExDOMapper deviceExDOMapper;

    private DeviceDataConverter deviceDataConverter = DeviceDataConverter.INSTANCE;

    @Override
    public void attach(DeviceDetail entity) {

    }

    @Override
    public void detach(DeviceDetail entity) {

    }

    @Override
    public DeviceDetail find(LongId generalId) {
        try {
//            DeviceDO deviceDO = deviceMapper.selectByPrimaryKey(generalId.getId().intValue());
//            DeviceExDO deviceExDO = deviceExDOMapper.selectByPrimaryKey(deviceDO.getDeviceUniqueId());
//            DeviceDetail deviceDetail = deviceDataConverter.fromData(deviceDO, deviceExDO);
//            deviceDetail.setDeviceId(new LongId(deviceDO.getDeviceId().longValue()));
//            return deviceDetail;
            return null;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void remove(DeviceDetail entity) {

    }

    @Override
    public void save(DeviceDetail entity) {
//        DeviceDO deviceDO = deviceDataConverter.toData(entity);
//        deviceMapper.updateByPrimaryKeySelective(deviceDO);
//        DeviceExDO deviceExDO = deviceDataConverter.toExData(entity);
//        deviceExDOMapper.updateByPrimaryKeySelective(deviceExDO);
    }
}
